<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>

    <script src="../Scripts/jquery-1.6.4/jquery.min.js"></script>
    <script src="../Scripts/signalr/jquery.signalR.min.js"></script>
</head>
<body>
<div>
    <h1>Echo service</h1>
    <div>
        <input type="text" id="text" />
        <button id="send">Send</button>
    </div>
    <script>
        var connection = $.connection("/signal");
        connection.logging = true;
        connection.debug = true;
        connection.transport = 'webSockets';

        console.log( connection)

        //客户端接收消息
        connection.received(function (data) {
            $(document.body).append(data+"<br/>");
        });
        //连接错误处理
        connection.error(function (err) {
            alert('与服务器连接报错:'+err.message);
        });
        //连接成功
        connection.start().done(function () {
            $('#send').click(function () {
                var val = $('#text').val();
                //向服务器端发送消息
                connection.send(val);
            });
        });
    </script>
</div>
</body>
</html>